//
//  KDHomeController.m
//  警用舆情平台
//
//  Created by 魏强 on 15/5/12.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "KDHomeController.h"
#import "HomeCellModel.h"
#import "KDHomePagefindAllTypeResult.h"
#import "KDHomeRequestTool.h"
#import "KDHomePageFindAllTypeParam.h"
#import "KDHomeThemeModel.h"
#import "KDHomeInfoModel.h"
#import "KDHomeThemeLinkModel.h"
#import "KDNewfeatureController.h"
#import "SVProgressHUD.h"
#import "KDBodyView.h"
#import "KDBodyViewModel.h"
#import "KDBaseBoard.h"
#import "KDBaseBoardModel.h"
#import "KDBaseBoardTool.h"
#import "GBSingleWebViewController.h"
#import "KDReportController.h"
#import "KDPatrolgetReportParam.h"
#import "KDHomeListPageCellModel.h"
#import "KDHomeThemeModel.h"
#import "GBAddFriendAnimation.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import "KDMRelationController.h"
#import "KDGetMonitorListParam.h"
//#define PAGE_NUMBER 4
#define Duration 0.4
//#define BTN_WIDTH (screenW - 40) / PAGE_NUMBER
CGFloat const HEADSCROLLH = 44.0;
#define RIGHTIMAGE_HEIGHT 40.0
#define BodyTag 10000

CGFloat const gestureMinimumTranslation = 20.0 ;
CGFloat const backViewW = 44.0;
typedef enum : NSInteger {
    
    kCameraMoveDirectionNone,
    
    kCameraMoveDirectionUp,
    
    kCameraMoveDirectionDown,
    
    kCameraMoveDirectionRight,
    
    kCameraMoveDirectionLeft
    
} CameraMoveDirection ;

@interface KDHomeController ()<UIScrollViewDelegate, UIAlertViewDelegate,KDBodyViewDelegate,baseboardDelegate, UIGestureRecognizerDelegate>

@property (nonatomic, assign) NSInteger pageNumber;


@property (nonatomic, assign) CameraMoveDirection direction;;

/***  头部的scrollView*/
@property (weak, nonatomic) UIScrollView *headScrollView;
/***  头部scrollView下面那个最大的scrollView*/
@property (nonatomic, strong) UIScrollView *bodyScrollView;

/***  被选中的主题btn*/
@property (nonatomic, strong) UIButton *selectBtn;

/**
 *  tableView的所有子主题的集合
 */
@property (nonatomic, strong) NSArray * infoArr;
/**
 * tableView的所有父主题的集合
 */
@property (nonatomic, strong) NSArray *parentInfo;

/***  用于装主题Btn的 */
@property (nonatomic, strong) NSArray *parentThemeArr;

/** navBar右边的自定义按钮*/
@property (nonatomic, strong) UIButton *rightBarBtn;
/**
 *  加载第几页
 */
@property (nonatomic, strong) NSString *page;
/** 右边弹出的选择界面*/
@property (nonatomic, strong) KDBaseBoard *baseView;
/** 右边弹出的选择界面的遮盖*/
@property (nonatomic, strong) UIButton *cover;

/**
 *  BaseBoard那边传过来的模型
 */
@property (nonatomic, strong) KDBaseBoardModel *baseBoardModel;
/** 时间格式转换器*/
@property (nonatomic, strong) NSDateFormatter *fmt;
@property (nonatomic, strong) KDHomeThemeModel *homeThemeModel;
/**
 *  当前的bodyView
 */
@property (nonatomic, strong) KDBodyView *currentBodyView;
/**
 *  请求后返回的地区信息
 */
@property (nonatomic, assign) NSInteger showReginType;
/**
 *  没有数据时的提示
 */
@property (nonatomic, weak) UIView * notice;
/**
 *  头部标题下面的红线
 */
@property (nonatomic, strong) UIView *redLine;

/**
 *  左滑手势
 */
@property (nonatomic, strong) UIPanGestureRecognizer *leftSwipeGestureRecognizer;

@property (nonatomic, weak) UIButton *backView;

@end

@implementation KDHomeController
#pragma mark - 懒加载区
- (NSString *)page
{
    if (!_page) {
        _page = @"1";
    }
    return _page;
}
//懒加载时期转换器
- (NSDateFormatter *)fmt
{
    if (!_fmt) {
        _fmt = [[NSDateFormatter alloc]init];
        _fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];;
        _fmt.dateFormat = @"yyyy-MM-dd";
    }
    return _fmt;
}
- (UIView *)redLine{
    if (!_redLine) {
        _redLine = [[UIView alloc]initWithFrame:CGRectMake(0, self.headScrollView.height -2, (screenW - 40) / self.parentThemeArr.count *1.0, 2)];
        [self.headScrollView addSubview:_redLine];
        _redLine.backgroundColor = KDColor;
    }
//    KDLog(@"%@",NSStringFromCGRect(_redLine.frame));
    [self.headScrollView bringSubviewToFront:_redLine];
    return _redLine;
}
- (KDBaseBoardModel *)baseBoardModel
{
    if (!_baseBoardModel) {
        _baseBoardModel = [[KDBaseBoardModel alloc]init];
        _baseBoardModel.webSrcType = @"0";
//        NSDate *newdate = [[NSDate date] initWithTimeInterval:- (24 *60 * 60 * 6 )sinceDate:[NSDate date]];
        _baseBoardModel.startTime = @"1970-01-01";//[self.fmt stringFromDate:newdate];
        _baseBoardModel.endTime = @"";
        _baseBoardModel.subtype = @"0";
        _baseBoardModel.timeIndex = @"9";
        _baseBoardModel.docType = @"0";
//        _baseBoardModel.idstr = [NSString stringWithFormat:@"%ld", self.homeThemeModel.ID];
        
        [KDBaseBoardTool saveBaseBoardModel:_baseBoardModel];
    }
    return _baseBoardModel;
}
@synthesize parentThemeArr = _parentThemeArr;
- (void)setParentThemeArr:(NSArray *)parentThemeArr
{
    _parentThemeArr = parentThemeArr;
    [[NSUserDefaults standardUserDefaults] setObject:parentThemeArr forKey:THEMEARR];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (NSArray *)parentInfo
{
    if (!_parentInfo) {
        _parentInfo = [NSArray new];
    }
    return _parentInfo;
}
- (NSArray *)infoArr
{
    if (!_infoArr) {
        _infoArr = [NSArray new];
    }
    return _infoArr;
}
/***  用于装主题Btn的 */
- (NSArray *)parentThemeArr
{
    if (!_parentThemeArr) {
        _parentThemeArr = [[NSUserDefaults standardUserDefaults] objectForKey:THEMEARR];
        if (!_parentThemeArr) {
            _parentThemeArr = @[@"涉警", @"维稳", @"巡查"];
        }
    }
    return _parentThemeArr;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - 版面设置区
- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    self.navigationItem.title = @"舆情预警";
    self.view.backgroundColor = BackGroundColor;
    [self setUpRightBarBtn];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(homeThemeModelChange:) name:@"homeThemeModelDidChangeValueNotification" object:nil];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //只在本控制器隐藏
    self.navigationController.navigationBar.hidden = YES;
}
/***  创建右边筛选按钮 */
- (void)setUpRightBarBtn
{
    UIButton *backView = [UIButton buttonWithType:UIButtonTypeCustom];
    backView.frame = CGRectMake(0, 0, backViewW, backViewW);
    [backView setImage:[UIImage imageNamed:@"leftArrow"] forState:UIControlStateNormal];
    [backView addTarget:self action:@selector(backViewClick) forControlEvents:UIControlEventTouchUpInside];
    self.backView = backView;
    [self.headScrollView addSubview:backView];
    
    UIButton *rightBarBtn = [[UIButton alloc]init];
    self.rightBarBtn = rightBarBtn;
    UIImage *image = [UIImage imageNamed:@"筛选"];
    rightBarBtn.width = RIGHTIMAGE_HEIGHT  ;
    rightBarBtn.height =  RIGHTIMAGE_HEIGHT;
    rightBarBtn.x = screenW -  rightBarBtn.width;
    rightBarBtn.y = (HEADSCROLLH - RIGHTIMAGE_HEIGHT) *0.5;
    rightBarBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightBarBtn setImage:image forState:UIControlStateNormal];;
    [rightBarBtn addTarget:self action:@selector(rightBarBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    rightBarBtn.selected = NO;
    [self.headScrollView addSubview:rightBarBtn];
}

/***  创建装头部topicBtn的scrollView */
- (void)setUpHeadScrollView
{
    //加一个挡板
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = [UIColor clearColor];
    [self.view addSubview:view];
    //初始化headScrollView
    UIScrollView *headScrollView = [[UIScrollView alloc]init];
    self.headScrollView = headScrollView;
    headScrollView.frame = CGRectMake(0, 20, screenW, HEADSCROLLH);
    
    headScrollView.contentSize = CGSizeMake(screenW - RIGHTIMAGE_HEIGHT, HEADSCROLLH);
    headScrollView.backgroundColor = KDColor;
    headScrollView.showsHorizontalScrollIndicator = NO;
    headScrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.headScrollView];
    //添加各主题子控件
    [self setUpHeadBtn];
}
- (void)setUpHeadBtn
{

    for (UIView *view in self.headScrollView.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    [self setUpRightBarBtn];
    CGFloat btnW = (self.headScrollView.width - RIGHTIMAGE_HEIGHT - backViewW);
    for (int i = 0; i < self.parentThemeArr.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.width = btnW/self.parentThemeArr.count *1.0;
        btn.height = _headScrollView.height;
        btn.x = i * btn.width + backViewW;
        btn.y = 0;
        btn.tag = 10+i;
        btn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        [btn setTitle:self.parentThemeArr[i] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(topicBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor: WQColor(203, 211, 221) forState:UIControlStateNormal];
        [btn setTitleColor: [UIColor whiteColor] forState:UIControlStateSelected];
        btn.backgroundColor = [UIColor clearColor];
        [_headScrollView addSubview:btn];
        if (btn.tag == 10) {
            self.selectBtn = btn;
            self.redLine.x = btn.x;
        }
    }
}

- (void)setUpBodyScrollView
{
    if (!self.bodyScrollView) {
        UIScrollView * bodyScrollView = [[UIScrollView alloc]init];
        self.bodyScrollView = bodyScrollView;
        bodyScrollView.frame = CGRectMake(0, CGRectGetMaxY(self.headScrollView.frame), screenW, screenH - CGRectGetMaxY(self.headScrollView.frame));
        bodyScrollView.delegate = self;
        bodyScrollView.contentSize = CGSizeMake(screenW * self.parentThemeArr.count, 1);
        bodyScrollView.showsHorizontalScrollIndicator = YES;
        bodyScrollView.pagingEnabled = YES;
        bodyScrollView.scrollEnabled = NO;
        bodyScrollView.showsVerticalScrollIndicator = YES;
        [self.view addSubview:bodyScrollView];
        //添加左滑手势
        self.leftSwipeGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
        self.leftSwipeGestureRecognizer.minimumNumberOfTouches = 2;
        self.leftSwipeGestureRecognizer.delegate = self;
//        self.leftSwipeGestureRecognizer.delaysTouchesBegan = YES;
        [self.bodyScrollView addGestureRecognizer:self.leftSwipeGestureRecognizer];
//        bodyScrollView.panGestureRecognizer = NO;
    }
    [self setUpDetailScrollView];
    //初始化主题
}
- (void)setUpDetailScrollView
{
    for (UIView *view in self.bodyScrollView.subviews) {
        if ([view isKindOfClass:[KDBodyView class]]) {
            [view removeFromSuperview];
        }
    }
    KDBodyView *body = [KDBodyView bodyViewWithFrame:CGRectMake(0 * screenW, 0, screenW, self.bodyScrollView.height)];
    body.delegate = self;
    KDHomeThemeLinkModel *model = self.infoArr[0];
    body.model = model;
    body.hasDetail = (model.info.count != 0);
    body.tag = BodyTag ;
    [self.bodyScrollView addSubview:body];
    self.currentBodyView = body;

}
/***  设置selectBtn的*/
- (void)setSelectBtn:(UIButton *)selectBtn
{
    _selectBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    _selectBtn = selectBtn;
    _selectBtn.selected = YES;
    [UIView animateWithDuration:1.0f animations:^{
        _selectBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    }];
}
/***  设置右边选择页面*/
-(void)setUpRightChoosePage
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if (!self.cover) {
        //加蒙板
        UIButton *cover = [[UIButton alloc]initWithFrame:window.bounds];
        self.cover = cover;
        cover.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        
        [cover addTarget:self action:@selector(coverClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_cover];
    }
    self.cover.frame = window.bounds;
//    KDLog(@"%@", NSStringFromCGRect(self.cover.frame));
    //创建底板
    if (!self.baseView) {
        KDBaseBoard *baseView = [KDBaseBoard baseboard];
        self.baseView = baseView;
        baseView.delegate = self;
        baseView.x = screenW;
        baseView.y = 64;
        baseView.height = screenH - baseView.y  ;
        baseView.width = screenW - screenW*0.175;
        baseView.mainPageType = @"预警";
        [_cover addSubview:baseView];
    }
    _baseView.showReginType = self.showReginType;
    _baseView.model.idstr = [NSString stringWithFormat:@"%ld", (long)self.currentBodyView.homeThemeModel.ID];
    _baseView.parentIdstr = [NSString stringWithFormat:@"%ld", (long)self.currentBodyView.model.ParentID];
    _baseView.height = screenH - _baseView.y  ;
    _baseView.width = screenW - screenW*0.175;
    [UIView animateWithDuration:0.4 animations:^{
        _baseView.x = screenW*0.175;
    }];
}

- (void)setUpNotise{
    UIView * notice = [[UIView alloc]initWithFrame:self.view.bounds];
    self.notice = notice;
    UIButton * noticeLb = [[UIButton alloc]init];
    noticeLb.width = screenW;
    noticeLb.height = notice.height;
    noticeLb.center = notice.center;
    notice.backgroundColor = BackGroundColor;
    [noticeLb setTitle:@"请点击屏幕，重新加载！" forState:UIControlStateNormal];
    [noticeLb setTitleColor:WQColor(178, 182, 184) forState:UIControlStateNormal];
    [noticeLb addTarget:self action:@selector(loadData) forControlEvents:UIControlEventTouchUpInside];
    [notice addSubview:noticeLb];
    [self.view addSubview:notice];
    [self.view bringSubviewToFront:notice];
}

#pragma mark - 事件点击区
/***  顶部主题Btn被点击 */
- (void)topicBtnDidClick:(UIButton *)btn
{
    self.selectBtn.selected = NO;
    self.selectBtn = btn;
     self.redLine.x = btn.x;
    //改变btn的显示状态
    NSInteger num = btn.tag -10;
    [self.bodyScrollView setContentOffset:CGPointMake(screenW*num, self.bodyScrollView.contentOffset.y) animated:YES];
    //每切换一次bodyView，baseView的idstr就要跟着对应上
    self.currentBodyView = (KDBodyView *)[self.bodyScrollView viewWithTag:num+BodyTag];
    if (!self.currentBodyView) {
        if (self.infoArr.count == 0) {
            [SVProgressHUD showErrorWithStatus:@"无数据" maskType:SVProgressHUDMaskTypeGradient];
                [self setUpNotise];
            return;
        }
        KDBodyView *body = [KDBodyView bodyViewWithFrame:CGRectMake(num * screenW, 0, screenW, self.bodyScrollView.height)];
        body.delegate = self;
        KDHomeThemeLinkModel *model;
        if (num < self.infoArr.count) {
            model = self.infoArr[num];
        }
        body.model = model;
        body.hasDetail = (model.info.count != 0);
        body.tag = BodyTag +num;
        [self.bodyScrollView addSubview:body];
        self.currentBodyView = body;
    }
    self.baseView.model.idstr = [NSString stringWithFormat:@"%ld",(long)self.currentBodyView.homeThemeModel.ID];
    self.baseView.parentIdstr = [NSString stringWithFormat:@"%ld", (long)self.currentBodyView.model.ParentID];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"HomeControllerTopicBtnDidClickNotyfication" object:nil userInfo:@{@"currentBodyView":self.currentBodyView}];
}

- (void)handleSwipes:(UIPanGestureRecognizer *)gesture{
    
    if (gesture.state == UIGestureRecognizerStateBegan )
    {
        _direction = kCameraMoveDirectionNone;
    }else if (gesture.state == UIGestureRecognizerStateChanged && _direction == kCameraMoveDirectionNone && gesture.minimumNumberOfTouches == 2)
    {
        if (!self.rightBarBtn) {
            [self setUpRightBarBtn];
            [self rightBarBtnClick:self.rightBarBtn];
        }else{
            [self setUpRightChoosePage];
        }
    }
}
/***  添加蒙板并显示右边页 */
- (void)rightBarBtnClick:(UIButton *)rightBarBtn
{
    if (!rightBarBtn.selected) {
        
        //设置右边的选择页面
        [self setUpRightChoosePage];
    } else
    {
        [self coverClick:self.cover];
    }
    rightBarBtn.selected = rightBarBtn.selected;
    
}
/***  去掉蒙板及右边页 */
- (void)coverClick:(UIButton *)cover
{
    [UIView animateWithDuration:0.4 animations:^{
        self.baseView.x = screenW;
    } completion:^(BOOL finished) {
//        [cover removeFromSuperview];
        self.cover.frame = CGRectMake(0, 0, 0, 0);
//        [self makeTabBarHidden:NO];
        self.rightBarBtn.selected = NO;
    }];
}

/**
 *  返回按钮被点击了
 */
- (void)backViewClick{
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 网络请求区

- (void)loadData
{
    [self.notice removeFromSuperview];
    WS(ws);
    //发送类别列表请求
    KDHomePageFindAllTypeParam *param = [[KDHomePageFindAllTypeParam alloc]init];
    param.method = @"findBusinessAllTypeList";
    KDAccount *accout = [KDAccountTool account];
//    accout.userName
    param.token = accout.token;
 
    [KDHomeRequestTool getAllTypeListWithParam:param success:^(KDHomePagefindAllTypeResult *responseObejct) {
//        KDLog(@"%@",responseObejct);
        if ([responseObejct.status isEqualToString:@"notlogin"]) {//如果被别人强制登陆了
            //写提示“该账号已在别处登录”
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"该账号已在别处登录" message:@"请重新登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alertView show];            
        }else{//正常情况下，就加载数据
            NSMutableArray *tempArr = [NSMutableArray array];
            ws.infoArr = @[responseObejct.info.model1,responseObejct.info.model2,responseObejct.info.model3, responseObejct.info.model16];
            int i = 0;
            for (KDHomeThemeModel *model in responseObejct.parentInfo) {
                
                [tempArr addObject:model.name];
                KDHomeThemeLinkModel *themeModel = ws.infoArr[i];
                themeModel.ParentID = model.ID;
                i++;
            }
            
            ws.parentInfo = responseObejct.parentInfo;
            
            for (KDHomeThemeLinkModel *model in ws.infoArr) {//将regintype赋值给model，然后他再给bodyView
                model.showReginType = responseObejct.regionType;
            }
            ws.parentThemeArr = tempArr;
            ws.showReginType = responseObejct.regionType;
            [ws setUpHeadScrollView];
            [ws setUpBodyScrollView];
        }
       
    } failure:^(NSError *error) {
        KDLog(@"%@",error);
        [self setUpNotise];
//        [messageView show];
    }];
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([alertView.title isEqualToString:@"该账号已在别处登录"]) {
        switch (buttonIndex) {
            case 0:
                [self presentViewController:[[KDNewfeatureController alloc]init] animated:YES completion:nil];
                break;
            default:
                break;
        }
    }
    
}

#pragma mark - KDBodyViewDelegate
//cell被点击了
- (void)KDBodyView:(KDBodyView *)bodyView WithKKDHomeListPageCellModel:(KDHomeListPageCellModel *)model didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GBSingleWebViewController *singleCtrl = [[GBSingleWebViewController alloc]init];
    singleCtrl.docid = model.docId;
    singleCtrl.titleee = model.title;
    singleCtrl.isCollect = model.isSave;
    singleCtrl.keyword = model.keywords;
    singleCtrl.whichPage = [NSString stringWithFormat:@"%ld",(long)indexPath.row] ;
    singleCtrl.url = model.url;
    singleCtrl.comeFrom = @"1";
    singleCtrl.report = model.isReport;
    singleCtrl.ori_content = model.content;
    singleCtrl.st = model.date;
    singleCtrl.ori_author = model.author;
    singleCtrl.ori_webname = model.source;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:singleCtrl animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
//上报按钮被点击了
- (void)KDBodyView:(KDBodyView *)bodyView WithKDHomeListPageCellModel:(KDHomeListPageCellModel *)model{
    KDReportController *reportCtrl = [[KDReportController alloc]init];
    KDPatrolgetReportParam *param = [[KDPatrolgetReportParam alloc]init];
    param.ori_url = model.url;
    param.ori_title = model.title;
    param.ori_content = model.content;
    param.st = model.date;
    param.doc_id = model.docId;
    if (model.author.length == 0) {
        param.ori_author = nil;
    }else{
        param.ori_author = model.author;
    }
    param.ori_webname = model.source;
    reportCtrl.param = param;
//    reportCtrl.type = 1;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:reportCtrl animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}

- (void)KDBodyView:(KDBodyView *)bodyView relationBtnClickWithModel:(KDHomeListPageCellModel *)model{
    KDMRelationController *relation = [[KDMRelationController alloc]init];
    KDGetMonitorListParam *param = [[KDGetMonitorListParam alloc]init];
    param.topicId = model.topicId;
    relation.param = param;
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:relation animated:YES];
    self.hidesBottomBarWhenPushed = NO;

}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
    return UIStatusBarAnimationSlide;
}
/**
 *  账号在别处登陆
 *
 */
- (void)bodyViewDidLoginedByOther:(KDBodyView *)bodyView{
    [self presentViewController:[[KDNewfeatureController alloc]init] animated:YES completion:nil];
}
#pragma mark - baseboardDelegate
- (void)baseBoard:(KDBaseBoard *)baseBoard confirmBtnDidClickWithBaseBoardModel:(KDBaseBoardModel *)model
{
    self.baseBoardModel = model;
    NSDictionary *dic = @{@"baseBoardModel":model, @"parentId":self.baseView.parentIdstr};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"HomeControllerConfirmBtnDidClickNoty" object:nil userInfo:dic];
    [self coverClick:self.cover];
    
}

#pragma mark -通知接收区
//换了tableView了
- (void)homeThemeModelChange:(NSNotification *)noty
{
//    KDLog(@"%@", noty.userInfo);
    KDHomeThemeModel *model = noty.userInfo[@"homeThemeModel"];
    KDBaseBoardModel *baseBoardmodel = [[KDBaseBoardModel alloc]init];
    baseBoardmodel.idstr = [NSString stringWithFormat:@"%ld", (long)model.ID];
    self.homeThemeModel.ID = baseBoardmodel.idstr.integerValue;
    self.baseView.model = baseBoardmodel;
//    [self.baseView setNeedsDisplay];
}
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch{
    
    if ([touch.view isKindOfClass:[UIScrollView class]]) {
        
        return NO;
    }else{
        return YES;
    }
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    
    return YES;
}
@end
